<?php

class Diapasone {

    private $from;
    private $to;
    private $num;

    private function __construct() {}

    /**
     * @return Diapasone
     */
    public static function createUnlimited() { return new UnlimitedDiapasone();}

    /**
     * @return Diapasone
     */
    public static function createFromTo($from, $to) {

        if ($from < 0)
            throw new Exception('from must be positive');

        if ($to < 0)
            throw new Exception('to must be positive');

        if ($from > $to) {
            list($to, $from) = array($from, $to);
        }

        $instance = new self;

        $instance->from = (int) $from;
        $instance->to   = (int) $to;
        $instance->num  = $to - $from;

        return $instance;
    }

    /**
     * @return Diapasone
     */
    public static function createFromNum($from, $num) {

        if ($from < 0)
            throw new Exception('from must be positive');

        if ($num < 0)
            throw new Exception('num must be positive');

        $instance = new self;

        $instance->from = (int) $from;
        $instance->num  = (int) $num;
        $instance->to   = $from + $num;

        return $instance;
    }

    public function getFrom() { return $this->from; }
    public function getTo() { return $this->to; }
    public function getNum() { return $this->num; }

    public function isUnlimited() { return false; }
}

class UnlimitedDiapasone extends Diapasone {

    public function __construct() {}

    public function getFrom() { throw new Exception(__METHOD__ . ' not implemented'); }
    public function getTo()   { throw new Exception(__METHOD__ . ' not implemented'); }
    public function getNum()  { throw new Exception(__METHOD__ . ' not implemented'); }

    public function isUnlimited() { return true; }
}

?>